﻿using System.Data;
using System.Data.SqlClient;

namespace MyWeb.Data
{
    public class CompanyController : SqlDataProvider
    {
        #region [Company_GetByAll]

        public DataTable Company_GetByAll()
        {
            return GetDataTable("sp_Company_GetByAll");
        }

        #endregion

        #region [Company_GetById]

        public DataTable Company_GetById(int  id)
        {
            var p1 = new SqlParameter("@id", id);
            return GetDataTable("sp_Company_GetById", p1);
        }

        #endregion

        #region [Company_Insert]

        public void Company_Insert(CompanyInfo company)
        {
            var p1 = new SqlParameter("@Name", company.Name);
            var p2 = new SqlParameter("@Address", company.Address);
            var p3 = new SqlParameter("@Phone", company.Phone);
            var p4 = new SqlParameter("@Email", company.Email);
            ExecuteStoreProcedure("sp_Company_Insert", p1, p2, p3, p4);
        }

        #endregion

        #region [Company_Update]

        public void Company_Update(CompanyInfo company)
        {
            var p0 = new SqlParameter("@id", company.Id);
            var p1 = new SqlParameter("@Name", company.Name);
            var p2 = new SqlParameter("@Address", company.Address);
            var p3 = new SqlParameter("@Phone", company.Phone);
            var p4 = new SqlParameter("@Email", company.Email);
            ExecuteStoreProcedure("sp_Company_Update",p0, p1, p2, p3, p4);
        }

        #endregion

        #region [Company_Delete]

        public void Company_Delete(int id)
        {
            var p1 = new SqlParameter("@id", id);
            ExecuteStoreProcedure("sp_Company_Delete", p1);
        }

        #endregion
    }
}